home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / RevRdist Folder / RevRdist / RevRdist src / TransSkel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-21  |  36.8 KB  |  1,515 lines  |  [TEXT/KAHL]

  1. /*
  2.     TransSkel version 2.01 - Transportable application skeleton
  3.  
  4.     TransSkel is public domain and was originally written by:
  5.  
  6.                 Paul DuBois
  7.                 Wisconsin Regional Primate Research Center
  8.                 1220 Capital Court
  9.                 Madison WI  53715-1299  USA
  10.  
  11.     UUCP:        {allegra,uunet}!uwvax!rhesus!dubois
  12.     Internet:    dubois@primate.wisc.edu
  13.  
  14.     Additional changes were made by
  15.  
  16.                 Owen Hartnett
  17.                 OHM Software Company
  18.                 163 Richard Drive
  19.                 Tiverton, RI 02878  USA
  20.  
  21.     UUCP:        {allegra,uunet}!brunix!omh
  22.     Internet:    omh@cs.brown.edu
  23.     CSNET:        omh@cs.brown.edu.CSNET
  24.  
  25.     Owen is also responsible for the port to Lightspeed Pascal.
  26.  
  27.     This version of TransSkel written for LightspeedC.  LightspeedC is a
  28.     trademark of:
  29.             THINK Technologies, Inc
  30.             420 Bedford Street  Suite 350
  31.             Lexington, MA  02173  USA
  32.  
  33.     Change history is in TSHistory.c
  34. */
  35.  
  36. /*
  37.     The following symbol controls support for dialogs.
  38.     "#define    supportDialogs" enables support.
  39.     "#undef        supportDialogs" disables support.
  40. */
  41.  
  42. # define    supportDialogs
  43.  
  44.  
  45. # ifdef        supportDialogs
  46. #    include    <Dialogs.h>
  47. # else
  48. #    include    <Windows.h>
  49. # endif
  50.  
  51. # include    <Events.h>
  52. # include    <Menus.h>
  53. # include    <AppleEvents.h>
  54.  
  55.  
  56. #include "C_config.h"
  57. #include "TransSkelProto.h"
  58.  
  59. # define    mBarHeight    20    /* menu bar height.  All window sizing
  60.                                code takes this into account */
  61.  
  62.  
  63. /*
  64.     New(TypeName) returns handle to new object, for any TypeName.
  65.     If there is insufficient memory, the result is nil.
  66. */
  67.  
  68. # define    New(x)    (x **) NewHandle ((Size) sizeof (x))
  69.  
  70.  
  71.  
  72. /*
  73.     Window and Menu handler types, constants, variables.
  74.  
  75.     whList and mhList are the lists of window and menu handlers.
  76.     whClobOnRmve and mhClobOnRmve are true if the handler disposal proc
  77.     is to be called when a handler is removed.  They are temporarily set
  78.     false when handlers are installed for windows or menus that already
  79.     have handlers - the old handler is removed WITHOUT calling the
  80.     disposal proc.
  81.  
  82.     Default lower limits on window sizing of 80 pixels both directions is
  83.     sufficient to allow text windows room to draw a grow box and scroll
  84.     bars without having the thumb and arrows overlap.  These values may
  85.     be changed if such a constraint is undesirable with SkelGrowBounds.
  86.     Default upper limits are for the Macintosh, not the Lisa, but are set
  87.     per machine in SkelInit.
  88. */
  89.  
  90. typedef struct WHandler    WHandler;
  91.  
  92. struct WHandler
  93. {
  94.     WindowPtr    whWind;            /* window/dialog to be handled  */
  95.     vProcPtr    whClobber;        /* data structure disposal proc */
  96.     vProcPtr    whMouse;        /* mouse-click handler proc     */
  97.     vProcPtr    whKey;            /* key-click handler proc       */
  98.     vProcPtr    whUpdate;        /* update handler proc          */
  99.     vProcPtr    whActivate;        /* activate event handler proc  */
  100.     vProcPtr    whClose;        /* close "event" handler proc   */
  101.     vProcPtr    whIdle;            /* main loop proc               */
  102. # ifdef    supportDialogs
  103.     vProcPtr    whEvent;        /* event proc                   */
  104. # endif
  105.     Rect        whGrow;            /* limits on window sizing      */
  106.     Boolean        whSized;        /* true = window was resized    */
  107.     Boolean        whFrontOnly;    /* true = idle only when active */
  108.     WHandler    **whNext;        /* next window handler          */
  109. };
  110.  
  111. static WHandler    **whList = nil;
  112. static Boolean    whClobOnRmve = true;
  113. static Rect        growRect = { 80, 80, 512, 342 - mBarHeight };
  114.  
  115. typedef struct MHandler    MHandler;
  116.  
  117. struct MHandler
  118. {
  119.     Integer        mhID;            /* menu id                     */
  120.     vProcPtr    mhSelect;        /* item selection handler proc */
  121.     vProcPtr    mhClobber;        /* menu disposal handler proc  */
  122.     MHandler    **mhNext;        /* next menu handler           */
  123. };
  124.  
  125.  
  126. static MHandler    **mhList = nil;            /* list of menu handlers */
  127. static Boolean    mhClobOnRmve = true;
  128.  
  129.  
  130. /*
  131.     Variables for default Apple menu handler.  appleID is set to 1 if
  132.     SkelApple is called and is the id of the Apple menu, appleAboutProc
  133.     is the procedure to execute if there is an About... item and it's
  134.     chosen from the Apple menu.  If doAbout is true, then the menu
  135.     contains the About... item, otherwise it's just desk accessories.
  136. */
  137.  
  138. static MenuHandle    appleMenu;
  139. static Integer        appleID = 0;
  140. static vProcPtr        appleAboutProc = nil;
  141. static Boolean        doAbout = false;
  142.  
  143.  
  144. /*
  145.     Miscellaneous
  146.  
  147.     screenPort points to the window manager port.
  148.  
  149.     doneFlag determines when SkelMain returns.  It is set by calling
  150.     SkelWhoa(), which is how the host requests a halt.
  151.  
  152.     pBkgnd points to a background procedure, to be run during event
  153.     processing.  Set it with SkelBackground.  If nil, there's no
  154.     procedure.
  155.  
  156.     pEvent points to an event-inspecting hook, to be run whenever an
  157.     event occurs.  Set it with SkelEventHook.  If nil, there's no
  158.     procedure.
  159.  
  160.     eventMask controls the event types requested in the GetNextEvent
  161.     call in SkelMain.
  162.  
  163.     diskInitPt is the location at which the disk initialization dialog
  164.     appears, if an uninitialized disk is inserted.
  165. */
  166.  
  167. static GrafPtr    screenPort;
  168. static Integer    doneFlag = false;
  169. static vProcPtr    pBkgnd = nil;
  170. static Boolean    (*pEvent)(EventRecord *) = nil;
  171. static Integer    eventMask = everyEvent;
  172. static Point    diskInitPt = { /* v = */ 120, /* h = */ 100 };
  173.  
  174. static WindowPtr    oldWindow = nil;
  175. static WHandler        **oldWDHandler = nil;
  176.  
  177.  
  178. # ifdef    supportDialogs
  179.  
  180. /*
  181.     dlogEventMask specifies events that are passed to dialogs.
  182.     Others are ignored.  Standard mask passes, mousedown, keydown,
  183.     autokey, update, activate and null events.  Null events are
  184.     controlled by bit 0 (always forced on).
  185. */
  186.  
  187. static Integer    dlogEventMask = 0x16b;
  188.  
  189. # endif
  190.  
  191.  
  192. /* -------------------------------------------------------------------- */
  193. /*                        Internal (private) Routines                        */
  194. /* -------------------------------------------------------------------- */
  195.  
  196. /* prototypes */
  197. static WHandler **GetWDHandler (WindowPtr theWind);
  198. static WHandler **GetWHandler (WindowPtr theWind);
  199. static WHandler **GetDHandler (DialogPtr theDialog);
  200. static void DoMenuCommand (Longint command);
  201. static void DoAppleItem (Integer item);
  202. static void DoAppleClobber (void);
  203. static void DoMouse (WHandler **h, EventRecord *theEvent);
  204. static void DoKey (WHandler **h, char ch, Integer mods);
  205. static void DoUpdate (WHandler **h);
  206. static void DoActivate (WHandler **h, int active);
  207. static void DoClose (WHandler **h);
  208. static void DoClobber (WHandler **h);
  209. static int  DoDialog (EventRecord *theEvent);
  210. static void TriggerUpdate (WHandler **h, GrafPtr grownPort);
  211. static void DoGrow (WHandler **h, GrafPtr growPort, Point startPt);
  212. static void DoZoom (WHandler **h, GrafPtr zoomPort, short partCode);
  213. static void DoEvent (EventRecord *theEvent);
  214.  
  215.  
  216. /*
  217.     Get handler associated with user or dialog window.
  218.     Return nil if window doesn't belong to any known handler.
  219.     This routine is absolutely fundamental to TransSkel.
  220. */
  221.  
  222.  
  223. static WHandler **GetWDHandler (WindowPtr theWind)
  224. {
  225. register WHandler    **h;
  226.  
  227.     if (theWind == oldWindow)
  228.         return(oldWDHandler);        /* return handler of cached window */
  229.  
  230.     for (h = whList; h != nil; h = (**h).whNext)
  231.     {
  232.         if ((**h).whWind == theWind)
  233.         {
  234.             oldWindow = theWind;    /* set cached window and handler */
  235.             oldWDHandler = h;
  236.             return (h);
  237.         }
  238.     }
  239.     return (nil);
  240. }
  241.  
  242.  
  243. /*
  244.     Get handler associated with user window.
  245.     Return nil if window doesn't belong to any known handler.
  246.     The order of the two tests is critical:  theWind might be nil.
  247. */
  248.  
  249. static WHandler **GetWHandler (WindowPtr theWind)
  250. {
  251. register WHandler    **h;
  252.  
  253.     if ((h = GetWDHandler (theWind)) != nil
  254.         && ((WindowPeek) theWind)->windowKind != dialogKind)
  255.     {
  256.             return (h);
  257.     }
  258.     return (nil);
  259. }
  260.  
  261.  
  262. # ifdef    supportDialogs
  263.  
  264. /*
  265.     Get handler associated with dialog window.
  266.     Return nil if window doesn't belong to any known handler.
  267.     The order of the two tests is critical:  theDialog might be nil.
  268. */
  269.  
  270. static WHandler **GetDHandler (DialogPtr theDialog)
  271. {
  272. register WHandler    **h;
  273.  
  274.     if ((h = GetWDHandler (theDialog)) != nil
  275.         && ((WindowPeek) theDialog)->windowKind == dialogKind)
  276.     {
  277.             return (h);
  278.     }
  279.     return (nil);
  280. }
  281.  
  282. # endif
  283.  
  284.  
  285. /*
  286.     General menu-handler.  Just passes selection to the handler's
  287.     select routine.  If the select routine is nil, selecting items from
  288.     the menu is a nop.
  289. */
  290.  
  291. static void
  292. DoMenuCommand (Longint command)
  293. {
  294. register Integer    menu;
  295. register Integer    item;
  296. register MHandler    **mh;
  297. register vProcPtr    p;
  298.  
  299.     menu = HiWord (command);
  300.     item = LoWord (command);
  301.     for (mh = mhList; mh != nil; mh = (**mh).mhNext)
  302.     {
  303.         if ((menu == (**mh).mhID) && ((p = (**mh).mhSelect) != nil))
  304.         {
  305.             (*p) (item);
  306.             break;
  307.         }
  308.     }
  309.     HiliteMenu (0);        /* command done, turn off menu hiliting */
  310. }
  311.  
  312.  
  313. /*
  314.     Apple menu handler
  315.  
  316.     DoAppleItem:  If the first item was chosen, and there's an "About..."
  317.     item, call the procedure associated with it (if not nil).  If there
  318.     is no "About..." item or the item was not the first one, then open
  319.     the associated desk accessory.  The port is saved and restored
  320.     because OpenDeskAcc does not always preserve it correctly.
  321.  
  322.     DoAppleClobber disposes of the Apple menu.
  323. */
  324.  
  325.  
  326. static void
  327. DoAppleItem (Integer item)
  328. {
  329. GrafPtr    curPort;
  330. Str255    str;
  331. Handle    h;
  332.  
  333.     if (doAbout && item == 1)
  334.     {
  335.         if (appleAboutProc != nil)
  336.             (*appleAboutProc) ();
  337.     }
  338.     else
  339.     {
  340.         GetPort (&curPort);
  341.         GetItem (appleMenu, item, str);        /* get DA name */
  342.         SetResLoad (false);
  343.         h = GetNamedResource ('DRVR', str);
  344.         SetResLoad (true);
  345.         if (h != nil)
  346.         {
  347.             ResrvMem (SizeResource (h) + 0x1000);
  348.             (void) OpenDeskAcc (str);            /* open it */
  349.         }
  350.         SetPort (curPort);
  351.     }
  352. }
  353.  
  354. static void
  355. DoAppleClobber (void)
  356. { DisposeMenu (appleMenu); }
  357.  
  358.  
  359. /* -------------------------------------------------------------------- */
  360. /*                        Window-handler routing routines                    */
  361. /*                                                                        */
  362. /*    See manual for discussion of port-setting behavior.  In general,    */
  363. /*    the current port is made to associate with the active window.        */
  364. /*    This is done in DoActivate for non-dialog windows, in DoDialog        */
  365. /*    for dialog windows.                                                    */
  366. /* -------------------------------------------------------------------- */
  367.  
  368.  
  369. /*
  370.     Pass local mouse coordinates, click time, and the modifiers flag
  371.     word to the handler.  Should not be necessary to set the port, as
  372.     the click is passed to the active window's handler.
  373. */
  374.  
  375. static void
  376. DoMouse (WHandler **h, EventRecord *theEvent)
  377. {
  378. register vProcPtr    p;
  379. Point                thePt;
  380.  
  381.     if (h != nil)
  382.     {
  383.         if ((p = (**h).whMouse) != nil)
  384.         {
  385.             thePt = theEvent->where;    /* make local copy */
  386.             GlobalToLocal (&thePt);
  387.             (*p) (thePt, theEvent->when, theEvent->modifiers);
  388.         }
  389.     }
  390. }
  391.  
  392.  
  393. /*
  394.     Pass the character and the modifiers flag word to the handler.
  395.     Should not be necessary to set the port, as the click is passed
  396.     to the active window's handler.
  397. */
  398.  
  399. static void
  400. DoKey (WHandler **h, char ch, Integer mods)
  401. {
  402. register vProcPtr    p;
  403.  
  404.     if (h != nil)
  405.     {
  406.         if ((p = (**h).whKey) != nil)
  407.             (*p) (ch, mods);
  408.     }
  409. }
  410.  
  411.  
  412. /*
  413.     Call the window updating procedure, passing to it an indicator whether
  414.     the window has been resized or not.  Then clear the flag, assuming
  415.     the update proc took whatever action was necessary to respond to
  416.     resizing.
  417.  
  418.     If the handler doesn't have any update proc, the Begin/EndUpdate
  419.     stuff is still done, to clear the update region.  Otherwise the
  420.     Window Manager will keep generating update events for the window,
  421.     stalling updates of other windows.
  422.  
  423.     Make sure to save and restore the port, as it's not always the
  424.     active window that is updated.
  425. */
  426.  
  427. static void
  428. DoUpdate (WHandler    **h)
  429. {
  430. register WHandler    **rh;
  431. register vProcPtr    p;
  432. register GrafPtr    updPort;
  433. GrafPtr                tmpPort;
  434.  
  435.     if ((rh = h) != nil)
  436.     {
  437.         GetPort (&tmpPort);
  438.         SetPort (updPort = (**rh).whWind);
  439.         BeginUpdate (updPort);
  440.         if ((p = (**rh).whUpdate) != nil)
  441.         {
  442.             (*p) ((**rh).whSized);
  443.             (**rh).whSized = false;
  444.         }
  445.         EndUpdate (updPort);
  446.         SetPort (tmpPort);
  447.     }
  448. }
  449.  
  450.  
  451. /*
  452.     Pass activate/deactivate notification to handler.  On activate,
  453.     set the port to the window coming active.  Normally this is done by
  454.     the user clicking in a window.
  455.  
  456.     *** BUT ***
  457.     Under certain conditions, a deactivate may be generated for a window
  458.     that has not had the port set to it by a preceding activate.  If an
  459.     application puts up window A, then window B in front of A, then
  460.     starts processing events, the first events will be a deactivate for A
  461.     and an activate for B.  Since it therefore can't be assumed the port
  462.     was set to A by an activate, the port needs to be set for deactivates
  463.     as well.
  464.  
  465.     This matters not a whit for the more usual cases that occur.  If a
  466.     deactivate for one window is followed by an activate for another, the
  467.     port will still be switched properly to the newly active window.  If
  468.     no activate follows the deactivate, the deactivated window is the last
  469.     one, and it doesn't matter what the port ends up set to, anyway.
  470. */
  471.  
  472. static void
  473. DoActivate (WHandler **h, int active)
  474. {
  475. register vProcPtr    p;
  476.  
  477.     if (h != nil)
  478.     {
  479.         SetPort ((**h).whWind);
  480.         if ((p = (**h).whActivate) != nil)
  481.             (*p) (active);
  482.     }
  483. }
  484.  
  485.  
  486. /*
  487.     Execute a window handler's close box proc.  The close proc for
  488.     handlers for temp windows that want to remove themselves when the
  489.     window is closed can call SkelRmveWind to dispose of the window
  490.     and remove the handler from the window handler list.  Thus, windows
  491.     may be dynamically created and destroyed without filling up the
  492.     handler list with a bunch of invalid handlers.
  493.  
  494.     If the handler doesn't have a close proc, just hide the window.
  495.     The host should provide some way of reopening the window (perhaps
  496.     a menu selection).  Otherwise the window will be lost from user
  497.     control if it is hidden, since it won't receive user-initiated
  498.     events.
  499.  
  500.     This is called both for regular and dialog windows.
  501.  
  502.     Since the close box of only the active window may be clicked, it
  503.     is not necessary to set the port.
  504. */
  505.  
  506. static void
  507. DoClose (WHandler    **h)
  508. {
  509. register WHandler    **rh;
  510. register vProcPtr    p;
  511.  
  512.     if ((rh = h) != nil)
  513.     {
  514.         if ((p = (**rh).whClose) != nil)
  515.             (*p) ();
  516.         else
  517.             HideWindow ((**rh).whWind);
  518.     }
  519. }
  520.  
  521.  
  522. /*
  523.     Execute a window handler's clobber proc.  This is called both
  524.     for regular and dialog windows.
  525.  
  526.     Must save, set and restore port, since any window (not just active
  527.     one) may be clobbered at any time.
  528.  
  529.     Don't need to check whether handler is nil, as in other handler
  530.     procedures, since this is only called by SkelRmveWind with a
  531.     known-valid handler.
  532. */
  533.  
  534. static void
  535. DoClobber (WHandler    **h)
  536. {
  537. register vProcPtr    p;
  538. GrafPtr                tmpPort;
  539.  
  540.     GetPort (&tmpPort);
  541.     SetPort ((**h).whWind);
  542.     if ((p = (**h).whClobber) != nil)
  543.         (*p) ();
  544.     SetPort (tmpPort);
  545. }
  546.  
  547.  
  548. # ifdef    supportDialogs
  549.  
  550. /* -------------------------------------------------------------------- */
  551. /*                            Dialog-handling routines                    */
  552. /* -------------------------------------------------------------------- */
  553.  
  554.  
  555. /*
  556.     Handle event if it's for a (modeless) dialog.  The event must be one
  557.     of those that is passed to dialogs according to dlogEventMask.
  558.     This mask can be set so that disk-inserts, for instance, don't
  559.     get eaten up.
  560.  
  561.     Examine event and set port if dialog window is coming active (for
  562.     normal windows, DoActivate sets the port; there's no such thing
  563.     for dialogs, so it's done here.)  When this is done, the trio
  564.     of GetPort/SetPort/SetPort calls commented out below doesn't appear
  565.     to be necessary any longer.  If you want to be cautious, it doesn't
  566.     hurt to uncomment them...
  567. */
  568.  
  569. static DoDialog (register EventRecord    *theEvent)
  570. {
  571. register WHandler    **dh;
  572. DialogPtr            theDialog;
  573. register Integer    what;
  574. Integer                item;
  575. GrafPtr                tmpPort;
  576. WindowPeek            w;
  577.  
  578. /*
  579.     handle command keys before they get to IsDialogEvent
  580. */
  581.  
  582.     what = theEvent->what;
  583.     if((what == keyDown || what == autoKey) && (theEvent->modifiers & cmdKey))
  584.     {
  585.         DoMenuCommand (MenuKey (theEvent->message & charCodeMask));
  586.         return (true);
  587.     }
  588.  
  589.     if (((1 << what) & dlogEventMask) && IsDialogEvent (theEvent))
  590.     {
  591.         /* ugly programming award semi-finalist follows */
  592.         if (theEvent->what == activateEvt            /* if activate */
  593.             && (theEvent->modifiers & activeFlag)    /* and coming active */
  594.             && (w=(WindowPeek) theEvent->message)->windowKind
  595.                     == dialogKind)
  596.         {
  597.             SetPort ((GrafPtr) w);
  598.         }
  599.         if ((DialogSelect (theEvent, &theDialog, &item)
  600.             || theEvent->what == activateEvt)
  601.            && (dh = GetDHandler (theDialog)) != nil
  602.            && (**dh).whEvent != nil)
  603.         {
  604.             /*GetPort (&tmpPort);*/
  605.             /*SetPort (theDialog);*/
  606.             (*(**dh).whEvent) (item, theEvent);
  607.             /*SetPort (tmpPort);*/
  608.         }
  609.         return (true);
  610.     }
  611.     return (false);
  612. }
  613.  
  614. # endif
  615.  
  616.  
  617. /* -------------------------------------------------------------------- */
  618. /*                            Event-handling routines                        */
  619. /* -------------------------------------------------------------------- */
  620.  
  621.  
  622. /*
  623.     Have either zoomed a window or sized it manually.  Invalidate
  624.     it to force an update and set the 'resized' flag in the window
  625.     handler true.  The port is assumed to be set to the port that changed
  626.     size.
  627. */
  628.  
  629. static void
  630. TriggerUpdate (WHandler    **h, GrafPtr grownPort)
  631. {
  632.     InvalRect (&grownPort->portRect);
  633.     if (h != nil)
  634.         (**h).whSized = true;
  635. }
  636.  
  637.  
  638. /*
  639.     Size a window.  If the window has a handler, use the grow limits
  640.     in the handler record, otherwise use the defaults.
  641.  
  642.     The portRect is invalidated to force an update event.  The handler's
  643.     update procedure should check the parameter passed to it to check
  644.     whether the window has changed size, if it needs to adjust itself to
  645.     the new size.  THIS IS A CONVENTION.  Update procs must notice grow
  646.     "events", there is no procedure specifically for such events.
  647.  
  648.     The clipping rectangle is not reset.  If the host application
  649.     keeps the clipping set equal to the portRect or something similar,
  650.     then it will have to arrange to treat window growing with more
  651.     care.
  652.  
  653.     Since the grow region of only the active window may be clicked,
  654.     it should not be necessary to set the port.
  655. */
  656.  
  657. static void
  658. DoGrow (WHandler **h, GrafPtr growPort, Point startPt)
  659. {
  660. Rect                r;
  661. register Longint    growRes;
  662.  
  663.     if (h != nil)
  664.         r = (**h).whGrow;
  665.     else
  666.         r = growRect;    /* use default */
  667.  
  668.     /* grow result non-zero if size change    */
  669.  
  670.     if (growRes = GrowWindow (growPort, startPt, &r))
  671.     {
  672.         SizeWindow (growPort, LoWord (growRes), HiWord (growRes), false);
  673.         TriggerUpdate (h, growPort);
  674.     }
  675. }
  676.  
  677.  
  678. /*
  679.     Zoom the current window.  Very similar to DoGrow
  680.  
  681.     Since the zoombox of only the active window may be clicked,
  682.     it should not be necessary to set the port.
  683. */
  684.  
  685. static void
  686. DoZoom (register WHandler **h, GrafPtr zoomPort, short partCode)
  687. {
  688.     ZoomWindow (zoomPort, partCode, 0);
  689.     TriggerUpdate (h, zoomPort);
  690. }
  691.  
  692.  
  693. /*
  694.     General event handler
  695. */
  696.  
  697. static void
  698. DoEvent (register EventRecord *theEvent)
  699. {
  700. Point                evtPt;
  701. GrafPtr                evtPort;
  702. register Integer    evtPart;
  703. register char        evtChar;
  704. register Integer    evtMods;
  705. register Longint    evtMsge;
  706. register WHandler    **h;
  707. Rect                r;
  708.  
  709. # ifdef    supportDialogs
  710.  
  711.     if(DoDialog (theEvent))
  712.         return;
  713.  
  714. # endif
  715.  
  716.     evtPt = theEvent->where;
  717.     evtMods = theEvent->modifiers;
  718.     evtMsge = theEvent->message;
  719.  
  720.     switch (theEvent->what)
  721.     {
  722.  
  723.         /*case nullEvent:
  724.             break;*/
  725. /*
  726.     Mouse click.  Get the window that the click occurred in, and the
  727.     part of the window.  GetWDHandler is called here, not GetWHandler, since
  728.     we need the handler for a window which might turn out to be a dialog
  729.     window, e.g., if the click is in a close box.
  730. */
  731.         case mouseDown:
  732.         {
  733.             evtPart = FindWindow (evtPt, &evtPort);
  734.             h = GetWDHandler (evtPort);
  735.  
  736.             switch (evtPart)
  737.             {
  738. /*
  739.     Click in a desk accessory window.  Pass back to the system.
  740. */
  741.                 case inSysWindow:
  742.                 {
  743.                     SystemClick (theEvent, evtPort);
  744.                     break;
  745.                 }
  746. /*
  747.     Click in menu bar.  Track the mouse and execute selected command,
  748.     if any.
  749. */
  750.                 case inMenuBar:
  751.                 {
  752.                     DoMenuCommand (MenuSelect (evtPt));
  753.                     break;
  754.                 }
  755. /*
  756.     Click in grow box.  Resize window.
  757. */
  758.                 case inGrow:
  759.                 {
  760.                     DoGrow (h, evtPort, evtPt);
  761.                     break;
  762.                 }
  763. /*
  764.     Click in title bar.  Drag the window around.  Leave at least
  765.     4 pixels visible in both directions.
  766.     Bug fix:  The window is selected first to make sure it's at least
  767.     activated (unless the command key is down-see Inside Macintosh).
  768.     DragWindow seems to call StillDown first, so that clicks in drag
  769.     regions while machine is busy don't otherwise bring window to front if
  770.     the mouse is already up by the time DragWindow is called.
  771. */
  772.                 case inDrag:
  773.                 {
  774.                     if (evtPort != FrontWindow () && (evtMods & cmdKey) == 0)
  775.                         SelectWindow (evtPort);
  776.                     r = screenPort->portRect;
  777.                     r.top += mBarHeight;            /* skip down past menu bar */
  778.                     InsetRect (&r, 4, 4);
  779.                     DragWindow (evtPort, evtPt, &r);
  780.                     break;
  781.                 }
  782. /*
  783.     Click in close box.  Call the close proc if the window has one.
  784. */
  785.                 case inGoAway:
  786.                 {
  787.                     if (TrackGoAway (evtPort, evtPt))
  788.                         DoClose (h);
  789.                     break;
  790.                 }
  791.  
  792. /*
  793.     Click in zoom box.  Track the click and then zoom the window if
  794.     necessary
  795. */
  796.                 case inZoomIn:
  797.                 case inZoomOut:
  798.                 {
  799.                     if (TrackBox (evtPort, evtPt, evtPart))
  800.                         DoZoom (h, evtPort, evtPart);
  801.                     break;
  802.                 }
  803. /*
  804.     Click in content region.  If the window wasn't frontmost (active),
  805.     just select it, otherwise pass the click to the window's mouse
  806.     click handler.
  807. */
  808.                 case inContent:
  809.                 {
  810.                     if (evtPort != FrontWindow ())
  811.                         SelectWindow (evtPort);
  812.                     else
  813.                         DoMouse (h, theEvent);
  814.                     break;
  815.                 }
  816.  
  817.             }
  818.             break;    /* mouseDown */
  819.         }
  820. /*
  821.     Key event.  If the command key was down, process as menu item
  822.     selection, otherwise pass the character and the modifiers flags
  823.     to the active window's key handler.
  824.  
  825.     If dialogs are supported, there's no check for command-key
  826.     equivalents, since that would have been checked in DoDialog.
  827. */
  828.         case keyDown:
  829.         case autoKey:
  830.         {
  831.             evtChar = evtMsge & charCodeMask;
  832.  
  833. # ifndef    supportDialogs
  834.  
  835.             if (evtMods & cmdKey)        /* try menu equivalent */
  836.             {
  837.                 DoMenuCommand (MenuKey (evtChar));
  838.                 break;
  839.             }
  840.  
  841. # endif
  842.  
  843.             DoKey (GetWHandler (FrontWindow ()), evtChar, evtMods);
  844.             break;
  845.         }
  846. /*
  847.     Update a window.
  848. */
  849.         case updateEvt:
  850.         {
  851.             DoUpdate (GetWHandler ((WindowPtr) evtMsge));
  852.             break;
  853.         }
  854. /*
  855.     Activate or deactivate a window.
  856. */
  857.         case activateEvt:
  858.         {
  859.             DoActivate (GetWHandler ((WindowPtr) evtMsge),
  860.                         ((evtMods & activeFlag) != 0));
  861.             break;
  862.         }
  863. /*
  864.     handle inserts of uninitialized disks
  865. */
  866.         case diskEvt:
  867.         {
  868.             if (HiWord (evtMsge) != noErr)
  869.             {
  870.                 DILoad ();
  871.                 (void) DIBadMount (diskInitPt, evtMsge);
  872.                 DIUnload ();
  873.             }
  874.             break;
  875.         }
  876.         case kHighLevelEvent:
  877.         {
  878.             (void) AEProcessAppleEvent(theEvent);
  879.             break;
  880.         }
  881.     }
  882. }
  883.  
  884.  
  885. /* -------------------------------------------------------------------- */
  886. /*                        Interface (public) Routines                        */
  887. /* -------------------------------------------------------------------- */
  888.  
  889.  
  890. /*
  891.     Initialize the various Macintosh Managers.
  892.     Set default upper limits on window sizing.
  893.     FlushEvents does NOT toss disk insert events, so that disks
  894.     inserted while the application is starting up don't result
  895.     in dead drives.
  896.  
  897.     noMasters is the number of times to call MoreMasters.  gzProc is
  898.     the address of a grow zone procedure to call if memory allocation
  899.     problems occur.  Pass nil if none to be used.
  900. */
  901.  
  902. void
  903. SkelInit (int noMasters, lProcPtr gzProc)
  904. {
  905.     while (noMasters-- > 0)
  906.         MoreMasters ();
  907.  
  908.     if (gzProc != nil)
  909.         SetGrowZone ((ProcPtr)gzProc);
  910.  
  911.     MaxApplZone ();
  912.     FlushEvents (everyEvent - diskMask, 0 );
  913.     InitGraf (&thePort);
  914.     InitFonts ();
  915.     InitWindows ();
  916.     InitMenus ();
  917.     TEInit ();
  918.     InitDialogs (nil);        /* no restart proc */
  919.     InitCursor ();
  920. /*
  921.     Set upper limits of window sizing to machine screen size.  Allow
  922.     for the menu bar.
  923. */
  924.     GetWMgrPort (&screenPort);
  925.     growRect.right = screenPort->portRect.right;
  926.     growRect.bottom = screenPort->portRect.bottom - mBarHeight;
  927. }
  928.  
  929.  
  930. /*
  931.     Main loop.
  932.  
  933.     Task care of DA's with SystemTask.
  934.     Run background task if there is one.
  935.     If there is an event, check for an event hook.  If there isn't
  936.     one defined, or if there is but it returns false, call the
  937.     general event handler.  (Hook returns true if TransSkel should
  938.     ignore the event.)
  939.     If no event, call the "no-event" handler for the front window and for
  940.     any other windows with idle procedures that are always supposed
  941.     to run.  This is done in such a way that it is safe for idle procs
  942.     to remove the handler for their own window if they want (unlikely,
  943.     but...)  This loop doesn't check whether the window is really
  944.     a dialog window or not, but it doesn't have to, because such
  945.     things always have a nil idle proc.
  946.  
  947.     doneFlag is reset upon exit.  This allows SkelMain to be called
  948.     repeatedly, or recursively.
  949.  
  950.     Null events are examined (in SkelMain) and passed to the event
  951.     handler.  This is necessary to make sure, if dialogs are supported,
  952.     that DialogSelect gets called repeatedly, or the caret won't blink
  953.     if a dialog has any editText items.
  954.  
  955.     Null events are not passed to any event-inspecting hook that may
  956.     be installed.
  957. */
  958.  
  959. void
  960. SkelMain (void)
  961. {
  962. EventRecord            theEvent;
  963. register WHandler    **wh, **wh2;
  964. register WindowPtr    w;
  965. Boolean                haveEvent;
  966. GrafPtr                tmpPort;
  967. register vProcPtr    p;
  968.  
  969.     while (!doneFlag)
  970.     {
  971.         SystemTask ();
  972.         if (pBkgnd != nil)
  973.             (*pBkgnd) ();
  974.  
  975. /*
  976.     Now watch carefully.  GetNextEvent calls SystemEvent to handle some
  977.     DA events, and returns false if the event was handled.  However, in
  978.     such cases the event record will still have the event that occurred,
  979.     *not* a null event, as you might reasonably expect.  So it's not
  980.     enough to look at haveEvent.
  981.  
  982.     Previous versions figured (wrongly) that haveEvent==false meant a null
  983.     event had occurred, and passed it through to DoEvent and DoDialog, so
  984.     that caret-blinking in dialog TextEdit items would occur.  But cmd-key
  985.     equivalents while DA windows were in front, in particular, allowed
  986.     already-processed DA events to get into DoEvent (because haveEvent
  987.     was false), and they got handled twice because when the event record
  988.     was examined, lo and behold, it had a cmd-key event!  So now this
  989.     logic is used:
  990.  
  991.     If have a real event, and there's no event hook or there is but it
  992.     doesn't handle the event, OR if the "non-event" is a true nullEvent,
  993.     then process it.
  994. */
  995.  
  996.         haveEvent = WaitNextEvent (eventMask, &theEvent, 1, nil);
  997.  
  998.         if ((haveEvent && (pEvent == nil || (*pEvent)(&theEvent) == false))
  999.                 || theEvent.what == nullEvent)
  1000.             DoEvent(&theEvent);
  1001.  
  1002. /*
  1003.     Run applicable idle procs.  Make sure to save and restore the port,
  1004.     since idle procs for the non-active window may be run.
  1005. */
  1006.  
  1007.         if (!haveEvent)
  1008.         {
  1009.             GetPort (&tmpPort);
  1010.             for (wh = whList; wh != nil; wh = wh2)
  1011.             {
  1012.                 wh2 = (**wh).whNext;
  1013.                 w = (**wh).whWind;
  1014.                 if ( (w == FrontWindow () || !(**wh).whFrontOnly ) )
  1015.                 {
  1016.                     SystemTask ();
  1017.                     if ((p = (**wh).whIdle) != nil)
  1018.                     {
  1019.                         SetPort (w);
  1020.                         (*p) ();
  1021.                     }
  1022.                 }
  1023.             }
  1024.             SetPort (tmpPort);
  1025.         }
  1026.     }
  1027.     doneFlag = false;
  1028. }
  1029.  
  1030.  
  1031. /*
  1032.     Tell SkelMain to stop
  1033. */
  1034.  
  1035. void
  1036. SkelWhoa (void) {
  1037.     doneFlag = true;
  1038. }
  1039.  
  1040.  
  1041. /*
  1042.     Clobber all the menu, window and dialog handlers
  1043. */
  1044.  
  1045. void
  1046. SkelClobber (void)
  1047. {
  1048.     while (whList != nil)
  1049.         SkelRmveWind ((**whList).whWind);
  1050.  
  1051.     while (mhList != nil)
  1052.         SkelRmveMenu (GetMHandle((**mhList).mhID));
  1053. }
  1054.  
  1055.  
  1056. /* -------------------------------------------------------------------- */
  1057. /*                        Menu-handler interface routines                    */
  1058. /* -------------------------------------------------------------------- */
  1059.  
  1060.  
  1061. /*
  1062.     Install handler for a menu.  Remove any previous handler for it.
  1063.     Pass the following parameters:
  1064.  
  1065.     theMenu    Handle to the menu to be handled.  Must be created by host.
  1066.     pSelect    Proc that handles selection of items from menu.  If this is
  1067.             nil, the menu is installed, but nothing happens when items
  1068.             are selected from it.
  1069.     pClobber Proc for disposal of handler's data structures.  Usually
  1070.             nil for menus that remain in menu bar until program
  1071.             termination.
  1072.  
  1073.     The menu is installed, and also drawn in the menu bar if drawBar true.
  1074.  
  1075.     Return 0 if no handler could be allocated, non-zero if successful.
  1076. */
  1077.  
  1078. SkelMenu (
  1079.     MenuHandle    theMenu,
  1080.     vProcPtr    pSelect,
  1081.     vProcPtr    pClobber,
  1082.     Boolean        drawBar)
  1083. {
  1084. register MHandler    **mh;
  1085.  
  1086.     mhClobOnRmve = false;
  1087.     SkelRmveMenu (theMenu);
  1088.     mhClobOnRmve = true;
  1089.  
  1090.     if ((mh = New (MHandler)) != nil)
  1091.     {
  1092.         (**mh).mhNext = mhList;
  1093.         mhList = mh;
  1094.         (**mh).mhID = (**theMenu).menuID;    /* get menu id number */
  1095.         (**mh).mhSelect = pSelect;            /* install selection handler */
  1096.         (**mh).mhClobber = pClobber;        /* install disposal handler */
  1097.         InsertMenu (theMenu, 0);            /* put menu at end of menu bar */
  1098.     }
  1099.     if (drawBar)
  1100.         DrawMenuBar ();
  1101.     return (mh != nil);
  1102. }
  1103.  
  1104.  
  1105. /*
  1106.     Remove a menu handler.  This calls the handler's disposal routine
  1107.     and then takes the handler out of the handler list and disposes
  1108.     of it.
  1109.  
  1110.     Note that the menu MUST be deleted from the menu bar before calling
  1111.     the clobber proc, because the menu bar will end up filled with
  1112.     garbage if the menu was allocated with NewMenu (see discussion of
  1113.     DisposeMenu in Menu Manager section of Inside Macintosh).
  1114. */
  1115.  
  1116. void
  1117. SkelRmveMenu (MenuHandle theMenu)
  1118. {
  1119. register Integer    mID;
  1120. register MHandler    **h, **h2;
  1121. register vProcPtr    p;
  1122.  
  1123.     mID = (**theMenu).menuID;
  1124.     if (mhList != nil)                /* if list empty, ignore */
  1125.     {
  1126.         if ((**mhList).mhID == mID)    /* is it the first element? */
  1127.         {
  1128.             h2 = mhList;
  1129.             mhList = (**mhList).mhNext;
  1130.         }
  1131.         else
  1132.         {
  1133.             for (h = mhList; h != nil; h = h2)
  1134.             {
  1135.                 h2 = (**h).mhNext;
  1136.                 if (h2 == nil)
  1137.                     return;                        /* menu not in list! */
  1138.                 if ((**h2).mhID == mID)            /* found it */
  1139.                 {
  1140.                     (**h).mhNext = (**h2).mhNext;
  1141.                     break;
  1142.                 }
  1143.             }
  1144.         }
  1145.         DeleteMenu (mID);
  1146.         DrawMenuBar ();
  1147.         if (mhClobOnRmve && (p = (**h2).mhClobber) != nil)
  1148.             (*p) (theMenu);                /* call disposal routine */
  1149.         DisposHandle ((Handle)h2);        /* get rid of handler record */
  1150.     }
  1151. }
  1152.  
  1153.  
  1154. /*
  1155.     Install a handler for the Apple menu.
  1156.  
  1157.     SkelApple is called if TransSkel is supposed to handle the apple
  1158.     menu itself.  aboutTitle is the title of the first item.  If nil,
  1159.     then only desk accessories are put into the menu.  If not nil, then
  1160.     the title is entered as the first item, followed by a gray line,
  1161.     then the desk accessories.
  1162.  
  1163.     SkelApple does not cause the menubar to be drawn, so if the Apple
  1164.     menu is the only menu, DrawMenuBar must be called afterward.
  1165.  
  1166.     No value is returned, unlike SkelMenu.  It is assumed that SkelApple
  1167.     will be called so early in the application that the call the SkelMenu
  1168.     is virtually certain to succeed.  If it doesn't, there's probably
  1169.     little hope for the application anyway.
  1170. */
  1171.  
  1172. void
  1173. SkelApple (StringPtr aboutTitle, vProcPtr aboutProc)
  1174. {
  1175.     appleID = 1;
  1176.     appleMenu = NewMenu (appleID, "\p\024");    /* 024 = apple character */
  1177.     if (aboutTitle != nil)
  1178.     {
  1179.         doAbout = true;
  1180.         AppendMenu (appleMenu, aboutTitle);    /* add About... item title */
  1181.         AppendMenu (appleMenu, "\p(-");        /* add gray line */
  1182.         appleAboutProc = aboutProc;
  1183.     }
  1184.     AddResMenu (appleMenu, 'DRVR');        /* add desk accessories */
  1185.     (void) SkelMenu (appleMenu, (vProcPtr)DoAppleItem, (vProcPtr)DoAppleClobber, false);
  1186. }
  1187.  
  1188.  
  1189. /* -------------------------------------------------------------------- */
  1190. /*                    Window-handler interface routines                    */
  1191. /* -------------------------------------------------------------------- */
  1192.  
  1193.  
  1194. /*
  1195.     Install handler for a window and set current port to it.  Remove
  1196.     any previous handler for it.  Pass the following parameters:
  1197.  
  1198.     theWind    Pointer to the window to be handled.  Must be created by host.
  1199.     pMouse    Proc to handle mouse clicks in window.  The proc will be
  1200.             passed the point (in local coordinates), the time of the
  1201.             click, and the modifier flags word.
  1202.     pKey    Proc to handle key clicks in window.  The proc will be passed
  1203.             the character and the modifier flags word.
  1204.     pUpdate    Proc for updating window.  TransSkel brackets calls to update
  1205.             procs with calls to BeginUpdate and EndUpdate, so the visRgn
  1206.             is set up correctly.  A flag is passed indicating whether the
  1207.             window was resized or not.  BY CONVENTION, the entire portRect
  1208.             is invalidated when the window is resized.  That way, the
  1209.             handler's update proc can redraw the entire content region
  1210.             without interference from BeginUpdate/EndUpdate.  The flag
  1211.             is set to false after the update proc is called; the
  1212.             assumption is made that it will notice the resizing and
  1213.             respond appropriately.
  1214.     pActivate Proc to execute when window is activated or deactivated.
  1215.             A int is passed to it which is true if the window is
  1216.             coming active, false if it's going inactive.
  1217.     pClose    Proc to execute when mouse clicked in close box.  Useful
  1218.             mainly to temp window handlers that want to know when to
  1219.             self-destruct (with SkelRmveWind).
  1220.     pClobber Proc for disposal of handler's data structures
  1221.     pIdle    Proc to execute when no events are pending.
  1222.     frontOnly True if pIdle should execute on no events only when
  1223.             theWind is frontmost, false if executes all the time.  Note
  1224.             that if it always goes, everything else may be slowed down!
  1225.  
  1226.     If a particular procedure is not needed (e.g., key events are
  1227.     not processed by a handler), pass nil in place of the appropriate
  1228.     procedure address.
  1229.  
  1230.     Return zero if no handler could be allocated, non-zero if successful.
  1231.     If zero is returned, the port will not have changed.
  1232. */
  1233.  
  1234. SkelWindow (
  1235.     WindowPtr    theWind,
  1236.     vProcPtr    pMouse,
  1237.     vProcPtr    pKey,
  1238.     vProcPtr    pUpdate,
  1239.     vProcPtr    pActivate,
  1240.     vProcPtr    pClose,
  1241.     vProcPtr    pClobber,
  1242.     vProcPtr    pIdle,
  1243.     Boolean        frontOnly)
  1244. {
  1245. register WHandler    **hHand, *hPtr;
  1246.  
  1247.     whClobOnRmve = false;
  1248.     SkelRmveWind (theWind);
  1249.     whClobOnRmve = true;
  1250.  
  1251. /*
  1252.     Get new handler, attach to list of handlers.  It is attached to the
  1253.     beginning of the list, which is simpler; the order is presumably
  1254.     irrelevant to the host, anyway.
  1255. */
  1256.  
  1257.     if ((hHand = New (WHandler)) != nil)
  1258.     {
  1259.         (**hHand).whNext = whList;
  1260.         whList = hHand;
  1261.  
  1262. /*
  1263.     Fill in handler fields
  1264. */
  1265.  
  1266.         hPtr = *hHand;
  1267.         hPtr->whWind = theWind;
  1268.         hPtr->whMouse = pMouse;
  1269.         hPtr->whKey = pKey;
  1270.         hPtr->whUpdate = pUpdate;
  1271.         hPtr->whActivate = pActivate;
  1272.         hPtr->whClose = pClose;
  1273.         hPtr->whClobber = pClobber;
  1274.         hPtr->whIdle = pIdle;
  1275.         hPtr->whFrontOnly = frontOnly;
  1276.         hPtr->whSized = false;
  1277.         hPtr->whGrow = growRect;
  1278.         SetPort (theWind);
  1279.     }
  1280.     return (hHand != nil);
  1281. }
  1282.  
  1283.  
  1284. /*
  1285.     Remove a window handler.  This calls the handler's disposal routine
  1286.     and then takes the handler out of the handler list and disposes
  1287.     of it.
  1288.  
  1289.     SkelRmveWind is also called by SkelRmveDlog.
  1290.  
  1291.     Note that if the window cache variable is set to the window whose
  1292.     handler is being clobbered, the variable must be zeroed.
  1293. */
  1294.  
  1295. void
  1296. SkelRmveWind (WindowPtr theWind)
  1297. {
  1298. register WHandler    **h, **h2;
  1299.  
  1300.     if (theWind == oldWindow)
  1301.         oldWindow = nil;
  1302.  
  1303.     if (whList != nil)        /* if list empty, ignore */
  1304.     {
  1305.         if ((**whList).whWind == theWind)    /* is it the first element? */
  1306.         {
  1307.             h2 = whList;
  1308.             whList = (**whList).whNext;
  1309.         }
  1310.         else
  1311.         {
  1312.             for (h = whList; h != nil; h = h2)
  1313.             {
  1314.                 h2 = (**h).whNext;
  1315.                 if (h2 == nil)
  1316.                     return;                        /* theWind not in list! */
  1317.                 if ((**h2).whWind == theWind)    /* found it */
  1318.                 {
  1319.                     (**h).whNext = (**h2).whNext;
  1320.                     break;
  1321.                 }
  1322.             }
  1323.         }
  1324.         if (whClobOnRmve)
  1325.             DoClobber (h2);            /* call disposal routine */
  1326.         DisposHandle ((Handle)h2);    /* get rid of handler record */
  1327.     }
  1328. }
  1329.  
  1330.  
  1331. # ifdef    supportDialogs
  1332.  
  1333. /* -------------------------------------------------------------------- */
  1334. /*                    Dialog-handler interface routines                    */
  1335. /* -------------------------------------------------------------------- */
  1336.  
  1337.  
  1338. /*
  1339.     Install a handler for a modeless dialog window and set the port
  1340.     to it.  Remove any previous handler for it. SkelDialog calls
  1341.     SkelWindow as a subsidiary to install a window handler, then sets
  1342.     the event procedure on return.
  1343.  
  1344.     Pass the following parameters:
  1345.  
  1346.     theDialog    Pointer to the dialog to be handled.  Must be created
  1347.             by host.
  1348.     pEvent    Event-handling proc for dialog events.
  1349.     pClose    Proc to execute when mouse clicked in close box.  Useful
  1350.             mainly to dialog handlers that want to know when to
  1351.             self-destruct (with SkelRmveDlog).
  1352.     pClobber Proc for disposal of handler's data structures
  1353.  
  1354.     If a particular procedure is not needed, pass nil in place of
  1355.     the appropriate procedure address.
  1356.  
  1357.     Return zero if no handler could be allocated, non-zero if successful.
  1358.     If zero is returned, the port will not have changed.
  1359. */
  1360.  
  1361. SkelDialog (
  1362.     DialogPtr    theDialog,
  1363.     vProcPtr    pEvent,
  1364.     vProcPtr    pClose,
  1365.     vProcPtr    pClobber)
  1366. {
  1367. int        swOk;
  1368.  
  1369.     if (SkelWindow (theDialog, nil, nil, nil, nil, pClose, pClobber, nil, false))
  1370.     {
  1371.         (**GetWDHandler (theDialog)).whEvent = pEvent;
  1372.         return (1);
  1373.     }
  1374.     return (0);
  1375. }
  1376.  
  1377.  
  1378. /*
  1379.     Remove a dialog and its handler
  1380. */
  1381.  
  1382. void
  1383. SkelRmveDlog (DialogPtr theDialog)
  1384. {
  1385.     SkelRmveWind (theDialog);
  1386. }
  1387.  
  1388. # endif
  1389.  
  1390.  
  1391. /* -------------------------------------------------------------------- */
  1392. /*                    Miscellaneous interface routines                    */
  1393. /* -------------------------------------------------------------------- */
  1394.  
  1395.  
  1396. /*
  1397.     Override the default sizing limits for a window, or, if theWind
  1398.     is nil, reset the default limits used by SkelWindow.
  1399. */
  1400.  
  1401. void
  1402. SkelGrowBounds (
  1403.     WindowPtr    theWind,
  1404.     Integer        hLo,
  1405.     Integer        vLo,
  1406.     Integer        hHi,
  1407.     Integer        vHi)
  1408. {
  1409. register WHandler    **h;
  1410. Rect                r;
  1411.  
  1412.     if (theWind == nil)
  1413.         SetRect (&growRect, hLo, vLo, hHi, vHi);
  1414.     else if ((h = GetWHandler (theWind)) != nil)
  1415.     {
  1416.         SetRect (&r, hLo, vLo, hHi, vHi);
  1417.         (**h).whGrow = r;
  1418.     }
  1419. }
  1420.  
  1421.  
  1422. /*
  1423.     Set the event mask.
  1424. */
  1425.  
  1426. void
  1427. SkelEventMask (Integer mask)
  1428. {
  1429.     eventMask = mask;
  1430. }
  1431.  
  1432.  
  1433. /*
  1434.     Return the event mask.
  1435. */
  1436.  
  1437. void
  1438. SkelGetEventMask (Integer *mask)
  1439. {
  1440.     *mask = eventMask;
  1441. }
  1442.  
  1443.  
  1444. /*
  1445.     Install a background task.  If p is nil, the current task is
  1446.     disabled.
  1447. */
  1448.  
  1449. void
  1450. SkelBackground (vProcPtr p)
  1451. {
  1452.     pBkgnd = p;
  1453. }
  1454.  
  1455.  
  1456. /*
  1457.     Return the current background task.  Return nil if none.
  1458. */
  1459.  
  1460. void
  1461. SkelGetBackground (vProcPtr *p)
  1462. {
  1463.     *p = pBkgnd;
  1464. }
  1465.  
  1466.  
  1467. /*
  1468.     Install an event-inspecting hook.  If p is nil, the hook is
  1469.     disabled.
  1470. */
  1471.  
  1472. void
  1473. SkelEventHook (Boolean    (*p)())
  1474. {
  1475.     pEvent = p;
  1476. }
  1477.  
  1478.  
  1479. /*
  1480.     Return the current event-inspecting hook.  Return nil if none.
  1481. */
  1482.  
  1483. void
  1484. SkelGetEventHook (Boolean    (**p)())
  1485. {
  1486.     *p = pEvent;
  1487. }
  1488.  
  1489.  
  1490. # ifdef    supportDialogs
  1491.  
  1492. /*
  1493.     Set the mask for event types that will be passed to dialogs.
  1494.     Bit 1 is always set, so that null events will be examined.
  1495.     (If this is not done, the caret does not blink in editText items.)
  1496. */
  1497.  
  1498. void
  1499. SkelDlogMask (Integer mask)
  1500. {
  1501.     dlogEventMask = mask | 1;
  1502. }
  1503.  
  1504.  
  1505. /*
  1506.     Return the current dialog event mask.
  1507. */
  1508.  
  1509. void
  1510. SkelGetDlogMask (Integer *mask)
  1511. {
  1512.     *mask = dlogEventMask;
  1513. }
  1514.  
  1515. # endif